#include <Magick++.h>
#include <fstream>
#include <iostream> 
#include "biplTypes.h"
#include "buildInFunc.h"

#define OPERATOR_TEST 0
#define BUILD_IN_FUNCTION_TEST 0

using namespace Magick; 

int main(int argc,char **argv) 
{
	std::ofstream outfile;
	outfile.open("testImageout.txt", std::ios::out);
	
	imageTypes img("1bs.jpg");
	std::cout<< img.width() << "\n";
	std::cout<< img.height()<< "\n";
	system("pause");
	return 0;
	imageTypes test = open("1bs.jpg");
	test *= pairTypes(100,100);
	test.show();
	//test.show();
	/*
	//imageTypes c = canvas(intTypes(400), intTypes(400));
	imageTypes img = open("lena.jpeg");
	test *= pairTypes(500, 500);
	img = compose(img, test);
	img.filename = stringTypes("testcompose");
	img.show();
	save(img, stringTypes("png"));
	*/
#if OPERATOR_TEST
	/*--------Test Image Object Oaperator--------*/
	Image imgTestOpSample("lena.jpg");
	imageTypes imgTest;
	outfile << "imgTest to Boolean is " << imgTest.toBoolean() << '\n';
	pairTypes samplePair(100.0, 100.0);
	degreeTypes sampleDeg(100.0);
	// Conversion to Boolean
	imageTypes imgTestOp = open("lena.jpg");
	outfile << "imgTestOp to Boolean is " << imgTestOp.toBoolean() << '\n';

	// |
	imageTypes imgTestAdd = imgTestOp | samplePair;
	if(imgTestAdd.getX() != 100.0 || imgTestAdd.getY() != 100.0) outfile << "|operator error!!\n";
	// &
	imageTypes imgTestSub = imgTestOp & sampleDeg;
	Image imgTestSubSample = imgTestOpSample;
	imgTestSubSample.rotate(100.0);
	if(!imgTestSub.getImage()->compare(imgTestSubSample)) outfile << "&operator error!\n";
	// *
	imageTypes imgTestMul = imgTestOp * samplePair;
	Image imgTestMulSample = imgTestOpSample;
	imgTestMulSample.scale(Geometry(100, 100));
	if(!imgTestMul.getImage()->compare(imgTestMulSample)) outfile << "*operator error!\n";
	// /
	imageTypes imgTestDiv = imgTestOp / samplePair;
	Image imgTestDivSample = imgTestOpSample;
	imgTestDivSample.shear(100.0, 100.0);
	if(!imgTestDiv.getImage()->compare(imgTestDivSample)) outfile << "/operator error!\n";
	// |=
	imgTestOp |= samplePair;
	if(imgTestOp.getX() != 100.0 || imgTestOp.getY() != 100.0) outfile << "|=operator error!!\n";
	// &=
	imgTestOp &= sampleDeg;
	imgTestOpSample.rotate(100.0);
	if(!imgTestOp.getImage()->compare(imgTestOpSample)) outfile << "&=operator error!\n";
	// *=
	imgTestOp *= samplePair;
	imgTestOpSample.scale(Geometry(100, 100));
	if(!imgTestOp.getImage()->compare(imgTestOpSample)) outfile << "*=operator error!\n";
	// /=
	imgTestOp /= samplePair;
	imgTestOpSample.shear(100.0, 100.0);
	if(!imgTestOp.getImage()->compare(imgTestOpSample)) outfile << "/=operator error!\n";
#endif

#if BUILD_IN_FUNCTION_TEST
	/*--------Test Build-In Functions--------*/
	// Test open and canvas
	imageTypes c = canvas(intTypes(100.0f), intTypes(100.0f));
	imageTypes img = open("lena.jpg");
	Image canvasSample("100x100","white");
	Image imgSample("lena.jpg");
	if(!c.getImage()->compare(canvasSample)) outfile << "canvas function error!\n";
	if(!img.getImage()->compare(imgSample)) outfile <<  "open function error!\n";

	// Test save
	save(img, stringTypes("bmp"));

	// Test compose
	c = compose(c, img);
	canvasSample.composite(imgSample, 0, 0);
	if(!c.getImage()->compare(canvasSample)) outfile <<  "compose function error!\n";

	// Test charcoal
	imageTypes charcoalImg = charcoal(img, intTypes(1));
	Image charcoalSample = imgSample;
	charcoalSample.charcoal(1);
	if(!charcoalImg.getImage()->compare(charcoalSample)) outfile <<  "charcoal function error!\n";

	// Test blur
	imageTypes blurImg = blur(img, intTypes(1), floatTypes(0.5));
	Image blurSample = imgSample;
	blurSample.blur(1, 0.5);
	if(!blurImg.getImage()->compare(blurSample)) outfile <<  "blur function error!\n";

	// Test sharpen
	imageTypes sharpenImg = sharpen(img, intTypes(1), floatTypes(0.5));
	Image sharpenSample = imgSample;
	sharpenSample.sharpen(1, 0.5);
	if(!sharpenImg.getImage()->compare(sharpenSample)) outfile <<  "sharpen function error!\n";

	// Test gray
	imageTypes grayImg = gray(img);
	Image graySample = imgSample;
	graySample.type(GrayscaleType);
	if(!grayImg.getImage()->compare(graySample)) outfile <<  "gray function error!\n";
	
	// Test crop
	pairTypes s_pnt(10.0f, 10.0f);
	pairTypes size(100.0f, 100.0f);
	imageTypes cropImg = crop(img, s_pnt, size);
	Image cropSample = imgSample;
	cropSample.crop(Geometry(100, 100, 10, 10));
	if(!cropImg.getImage()->compare(cropSample)) outfile <<  "crop function error!\n";

	// Test noise
	imageTypes noiseImg = noise(img);
	//noiseImg.show();
	Image noiseSample = imgSample;
	noiseSample.addNoise(GaussianNoise);
	//noiseSample.write("win:");
	if(!noiseImg.getImage()->compare(noiseSample)) outfile <<  "noise function error!\n";

	// Test normalize
	imageTypes normalizeImg = normalize(img);
	Image normalizeSample = imgSample;
	normalizeSample.normalize();
	if(!normalizeImg.getImage()->compare(normalizeSample)) outfile <<  "normalize function error!\n";
	
	// Test label function
	imageTypes test = label(stringTypes("testtype"), stringTypes("Tahoma"), intTypes(100), floatTypes(1.0f), floatTypes(0), floatTypes(0));
	save(test, stringTypes("png"));

	// Test convolve
	imageTypes convolveImg = convolve(img, 0, -1, 0, -1, 4, -1, 0, -1, 0);
	Image convolveSample = imgSample;
	double kernel[9] = {0, -1, 0, -1, 4, -1, 0, -1, 0};
	convolveSample.convolve(3, kernel);
	if(!convolveImg.getImage()->compare(convolveSample)) outfile <<  "convolve function error!\n";

	//system("pause");
#endif
	outfile.close();
	return 0;
}
